package prickworlds.gui;

import java.util.ArrayList;


/**
 * Class to handle focus requests and shit
 * 
 * @author Faruk Acibal, Richard Dziambor, Christian Holzreuter, Nicolas Winkler
 * 
 */
public class FocusDealer extends Focusable {
	/**
	 * index of the <code>Focusable</code> that is currently focused
	 */
	private int focus;

	/**
	 * list of all children <code>Focusable</code>
	 */
	private ArrayList<Focusable> focusables;

	/**
	 * creates a child {@link FocusDealer}
	 * 
	 * @param focusDealer
	 *            the parent dealer
	 */
	public FocusDealer(FocusDealer focusDealer) {
		super(focusDealer);
		focusables = new ArrayList<Focusable>();
		focus = -1;
	}

	/**
	 * default constructor
	 */
	public FocusDealer() {
		super();
		focusables = new ArrayList<Focusable>();
		focus = -1;
	}

	/**
	 * adds a new {@link Focusable} to the dealer list
	 * 
	 * @param focusable
	 *            the {@link Focusable} to add
	 */
	public void add(Focusable focusable) {
		focusables.add(focusable);
		if (focus == -1)
			focus = focusables.size() - 1;
	}

	/**
	 * removes a focusable from the dealer list
	 * 
	 * @param focusable
	 *            the {@link Focusable} to remove
	 */
	public void remove(Focusable focusable) {
		int index = focusables.indexOf(focusable);
		focusables.remove(index);
		if (focus >= index)
			focus--;
	}

	/**
	 * function to handle focusRequests
	 * 
	 * @param focusable
	 *            the <link>Focusable</link> that asks for the focus
	 * @return true if the focus state was changed
	 */
	public boolean requestFocus(Focusable focusable) {
		return false;
	}

}
